import { defineStore } from 'pinia'
import request from '@/utils/request'
import { IApiRes, bannerType, NewsListType, HotListType } from '@/types/data'
export default defineStore('home', {
  state: () => {
    return {
      // num: 100
     bannerList: [] as bannerType[],
     newsList: [] as NewsListType[],
     hotList: [] as HotListType[]
    }
  },
  actions: {
    // 获取轮播图数据
   async getBannerList(){
    const res = await request.get<IApiRes<bannerType[]>>('/home/banner')
    this.bannerList =res.data.result
   },
  //  新鲜好物
  async getHomeNewList() {
    const res = await request.get<IApiRes<NewsListType[]>>('/home/new')
    this.newsList = res.data.result
  },
  //  人气推荐
  async getHotList() {
    const res = await request.get<IApiRes<HotListType[]>>('/home/hot')
    this.hotList = res.data.result
  }
  },
  getters: {

  }
})